/*
 *  Copyright 2005 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.model.core.statistics;

import com.blandware.atleap.model.core.BaseObject;
import com.blandware.atleap.model.core.ContentResource;
import com.blandware.atleap.model.core.Page;
import com.blandware.atleap.model.core.User;

import java.util.Date;

/**
 * <p>Represents visit made by someone to our site.</p>
 * <p><a href="Visit.java.html"><i>View source</i></a></p>
 *
 * @author Roman Puchkovskiy <a href="mailto:roman.puchkovskiy@blandware.com">
 *         &lt;roman.puchkovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.4 $ $Date: 2006/06/16 09:36:41 $
 * @struts.form include-all="false" extends="BaseForm"
 * @hibernate.class table="`al_core_visit`" lazy="false"
 */
public class Visit extends BaseObject {

    /**
     * Visit ID
     */
    protected Long id;

    /**
     * URL
     */
    protected String url;

    /**
     * Visited page
     */
    protected Page page;

    /**
     * Visited resource
     */
    protected ContentResource contentResource;

    /**
     * Referrer URL
     */
    protected String referrerUrl;

    /**
     * Referrer domain
     */
    protected String referrerDomain;

    /**
     * Search engine ID
     */
    protected Integer searchEngineId;

    /**
     * Search phrase
     */
    protected String searchPhrase;

    /**
     * Session number
     */
    protected Integer sessionNumber;

    /**
     * Visitor number
     */
    protected Integer visitorNumber;

    /**
     * Visitor IP
     */
    protected String ip;

    /**
     * Visitor browser ID
     */
    protected Integer browserId;

    /**
     * Visitor OS ID
     */
    protected Integer osId;

    /**
     * Robot ID
     */
    protected Integer robotId;

    /**
     * Visitor user
     */
    protected User user;

    /**
     * Visitor screen width
     */
    protected Integer screenWidth;

    /**
     * Visitor screen height
     */
    protected Integer screenHeight;

    /**
     * Visitor screen color depth
     */
    protected Integer colorDepth;

    /**
     * Visit date
     */
    protected Date date;

    /**
     * Whether this visit is entry point of its session
     */
    protected Boolean entryPoint;

    /**
     * Whether this visit is exit point of its session
     */
    protected Boolean exitPoint;

    /**
     * User agent
     */
    protected UserAgent userAgent;

    /**
     * Constructs a Visit instance
     */
    public Visit() {
    }

    /**
     * Returns visit ID.
     *
     * @return ID
     * @struts.form-field
     * @hibernate.id column="`id`"
	 * generator-class="increment" unsaved-value="null"
     */
    public Long getId() {
        return id;
    }

    /**
     * Sets visit ID.
     *
     * @param id ID to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * Returns requested URL of this visit.
     *
     * @return URL
     * @hibernate.property
	 * @hibernate.column name="`url`" not-null="false" unique="false"
     * length="252"
     */
    public String getUrl() {
        return url;
    }

    /**
     * Sets requested URL of this visit.
     *
     * @param url URL to set
     */
    public void setUrl(String url) {
        this.url = url;
    }

    /**
     * Returns a page to which visit was made.
     *
     * @return visited page
	 * @hibernate.many-to-one column="`page_id`" not-null="false"
     * outer-join="false" lazy="false"
     */
    public Page getPage() {
        return page;
    }

    /**
     * Sets a page to which visit was made.
     *
     * @param page page to set
     */
    public void setPage(Page page) {
        this.page = page;
    }

    /**
     * Returns a resource to which visit was made.
     *
     * @return visited resource
     * @hibernate.many-to-one column="`resource_id`" not-null="false"
     * outer-join="false" lazy="false"
     */
    public ContentResource getContentResource() {
        return contentResource;
    }

    /**
     * Sets a resource to which visit was made.
     *
     * @param resource resource to set
     */
    public void setContentResource(ContentResource resource) {
        this.contentResource = resource;
    }

    /**
     * Returns referrer URL
     *
     * @return referrer URL
     * @hibernate.property
	 * @hibernate.column name="`referrer_url`" not-null="false" unique="false"
     * length="252"
     */
    public String getReferrerUrl() {
        return referrerUrl;
    }

    /**
     * Sets referrer URL
     *
     * @param referrerUrl
     */
    public void setReferrerUrl(String referrerUrl) {
        this.referrerUrl = referrerUrl;
    }

    /**
     * Returns referrer domain.
     *
     * @return referrer domain
     * @hibernate.property
     * @hibernate.column name="`referrer_domain`" not-null="false"
     * unique="false" length="252"
     */
    public String getReferrerDomain() {
        return referrerDomain;
    }

    /**
     * Sets referrer domain.
     *
     * @param referrerDomain domain to set
     */
    public void setReferrerDomain(String referrerDomain) {
        this.referrerDomain = referrerDomain;
    }

    /**
     * Returns search engine ID.
     *
     * @return search engine ID
     * @hibernate.property column="`search_engine`" not-null="false"
     */
    public Integer getSearchEngineId() {
        return searchEngineId;
    }

    /**
     * Sets search engine ID.
     *
     * @param searchEngineId ID to set
     */
    public void setSearchEngineId(Integer searchEngineId) {
        this.searchEngineId = searchEngineId;
    }

    /**
     * Returns search phrase.
     *
     * @return search phrase
     * @hibernate.property
	 * @hibernate.column name="`search_phrase`" not-null="false" unique="false"
     * length="252"
     */
    public String getSearchPhrase() {
        return searchPhrase;
    }

    /**
     * Sets search phrase.
     *
     * @param searchPhrase search phrase to set
     */
    public void setSearchPhrase(String searchPhrase) {
        this.searchPhrase = searchPhrase;
    }

    /**
     * Returns a number that identifies a session.
     *
     * @return session number
     * @hibernate.property column="`session_number`" not-null="true"
     */
    public Integer getSessionNumber() {
        return sessionNumber;
    }

    /**
     * Sets a number that identifies a session.
     *
     * @param sessionNumber number to set
     */
    public void setSessionNumber(Integer sessionNumber) {
        this.sessionNumber = sessionNumber;
    }

    /**
     * Returns a number that identifies a visitor.
     *
     * @return visitor number
     * @hibernate.property column="`visitor_number`" not-null="true"
     */
    public Integer getVisitorNumber() {
        return visitorNumber;
    }

    /**
     * Sets a number that identifies a visitor.
     *
     * @param visitorNumber number to set
     */
    public void setVisitorNumber(Integer visitorNumber) {
        this.visitorNumber = visitorNumber;
    }

    /**
     * Returns visitor IP.
     *
     * @return IP
     * @hibernate.property
	 * @hibernate.column name="`ip`" not-null="false" unique="false"
     * length="252"
     */
    public String getIp() {
        return ip;
    }

    /**
     * Sets visitor IP.
     *
     * @param ip IP to set
     */
    public void setIp(String ip) {
        this.ip = ip;
    }

    /**
     * Returns visitor browser ID.
     *
     * @return browser ID
     * @hibernate.property column="`browser`" not-null="false"
     */
    public Integer getBrowserId() {
        return browserId;
    }

    /**
     * Sets visitor browser ID.
     *
     * @param browserId browser ID to set
     */
    public void setBrowserId(Integer browserId) {
        this.browserId = browserId;
    }

    /**
     * Returns visitor OS ID.
     *
     * @return OS ID
     * @hibernate.property column="`os`" not-null="false"
     */
    public Integer getOsId() {
        return osId;
    }

    /**
     * Sets visitor OS ID.
     *
     * @param osId OS ID to set
     */
    public void setOsId(Integer osId) {
        this.osId = osId;
    }

    /**
     * Returns robot ID.
     *
     * @return robot ID
     * @hibernate.property column="`robot`" not-null="false"
     */
    public Integer getRobotId() {
        return robotId;
    }

    /**
     * Sets robot ID.
     *
     * @param robotId ID to set
     */
    public void setRobotId(Integer robotId) {
        this.robotId = robotId;
    }

    /**
     * Returns a visitor user.
     *
     * @return visitor user
     * @hibernate.many-to-one column="`username`" not-null="false"
     * outer-join="false" lazy="false"
     */
    public User getUser() {
        return user;
    }

    /**
     * Sets a visitor user.
     *
     * @param user visitor user to set
     */
    public void setUser(User user) {
        this.user = user;
    }

    /**
     * Returns visitor screen width.
     *
     * @return screen width
     * @hibernate.property column="`screen_width`" not-null="false"
     */
    public Integer getScreenWidth() {
        return screenWidth;
    }

    /**
     * Sets visitor screen width.
     *
     * @param screenWidth screen width to set
     */
    public void setScreenWidth(Integer screenWidth) {
        this.screenWidth = screenWidth;
    }

    /**
     * Returns visitor screen height.
     *
     * @return screen height
     * @hibernate.property column="`screen_height`" not-null="false"
     */
    public Integer getScreenHeight() {
        return screenHeight;
    }

    /**
     * Sets visitor screen height.
     *
     * @param screenHeight screen height to set
     */
    public void setScreenHeight(Integer screenHeight) {
        this.screenHeight = screenHeight;
    }

    /**
     * Returns visitor screen color depth.
     *
     * @return color depth
     * @hibernate.property column="`color_depth`" not-null="false"
     */
    public Integer getColorDepth() {
        return colorDepth;
    }

    /**
     * Sets visitor screen color depth.
     *
     * @param colorDepth color depth to set
     */
    public void setColorDepth(Integer colorDepth) {
        this.colorDepth = colorDepth;
    }

    /**
     * Returns screen info as a string (like this: WIDTHxHEIGHTxDEPTH).
     *
     * @return screen info
     */
    public String getScreenInfo() {
        String result = "";
        if (screenWidth != null && screenHeight != null && colorDepth != null) {
            result = screenWidth.toString() + 'x' + screenHeight
                    + 'x' + colorDepth;
        }
        return result;
    }

    /**
     * Returns visit date.
     *
     * @return date
     * @hibernate.property type="timestamp"
	 * @hibernate.column name="`date`"  not-null="true"
     * unique="false"
     */
    public Date getDate() {
        return date;
    }

    /**
     * Sets visit date.
     *
     * @param date date to set
     */
    public void setDate(Date date) {
        this.date = date;
    }

    /**
     * Returns whether this visit is entry point of its session.
     *
     * @return whether this visit is entry point of its session
     * @struts.form-field
	 * @hibernate.property column="`entry_point`" not-null="true"
     * type="true_false"
     */
    public Boolean getEntryPoint() {
        return entryPoint;
    }

    /**
     * Sets whether this visit is entry point of its session.
     *
     * @param entryPoint sets whether this visit is entry point of its session
     */
    public void setEntryPoint(Boolean entryPoint) {
        this.entryPoint = entryPoint;
    }

    /**
     * Returns whether this visit is exit point of its session.
     *
     * @return whether this visit is exit point of its session
     * @struts.form-field
	 * @hibernate.property column="`exit_point`" not-null="true"
     * type="true_false"
     */
    public Boolean getExitPoint() {
        return exitPoint;
    }

    /**
     * Sets whether this visit is exit point of its session.
     *
     * @param exitPoint sets whether this visit is exit point of its session
     */
    public void setExitPoint(Boolean exitPoint) {
        this.exitPoint = exitPoint;
    }

    /**
     * Returns user agent.
     *
     * @return user agent
     */
    public UserAgent getUserAgent() {
        return userAgent;
    }

    /**
     * Sets user agent.
     *
     * @param userAgent user agent to set
     */
    public void setUserAgent(UserAgent userAgent) {
        this.userAgent = userAgent;
    }

    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Visit)) {
            return false;
        }

        final Visit visit = (Visit) o;

        if (browserId != null
                ? !browserId.equals(visit.browserId) : visit.browserId != null) {
            return false;
        }
        if (colorDepth != null
                ? !colorDepth.equals(visit.colorDepth) : visit.colorDepth != null) {
            return false;
        }
        if (contentResource != null
                ? !contentResource.equals(visit.contentResource)
                : visit.contentResource != null) {
            return false;
        }
        if (date != null ? !date.equals(visit.date) : visit.date != null) {
            return false;
        }
        if (entryPoint != null
                ? !entryPoint.equals(visit.entryPoint) : visit.entryPoint != null) {
            return false;
        }
        if (exitPoint != null
                ? !exitPoint.equals(visit.exitPoint) : visit.exitPoint != null) {
            return false;
        }
        if (ip != null ? !ip.equals(visit.ip) : visit.ip != null) {
            return false;
        }
        if (osId != null ? !osId.equals(visit.osId) : visit.osId != null) {
            return false;
        }
        if (page != null ? !page.equals(visit.page) : visit.page != null) {
            return false;
        }
        if (referrerDomain != null
                ? !referrerDomain.equals(visit.referrerDomain)
                : visit.referrerDomain != null) {
            return false;
        }
        if (referrerUrl != null
                ? !referrerUrl.equals(visit.referrerUrl)
                : visit.referrerUrl != null) {
            return false;
        }
        if (robotId != null ? !robotId.equals(visit.robotId) : visit.robotId
                != null) {
            return false;
        }
        if (screenHeight != null
                ? !screenHeight.equals(visit.screenHeight)
                : visit.screenHeight != null) {
            return false;
        }
        if (screenWidth != null
                ? !screenWidth.equals(visit.screenWidth)
                : visit.screenWidth != null) {
            return false;
        }
        if (searchEngineId != null
                ? !searchEngineId.equals(visit.searchEngineId)
                : visit.searchEngineId != null) {
            return false;
        }
        if (searchPhrase != null
                ? !searchPhrase.equals(visit.searchPhrase)
                : visit.searchPhrase != null) {
            return false;
        }
        if (sessionNumber != null
                ? !sessionNumber.equals(visit.sessionNumber)
                : visit.sessionNumber != null) {
            return false;
        }
        if (url != null ? !url.equals(visit.url) : visit.url != null) {
            return false;
        }
        if (user != null ? !user.equals(visit.user) : visit.user != null) {
            return false;
        }
        if (visitorNumber != null
                ? !visitorNumber.equals(visit.visitorNumber)
                : visit.visitorNumber != null) {
            return false;
        }

        return true;
    }

    public int hashCode() {
        int result;
        result = (url != null ? url.hashCode() : 0);
        result = 29 * result + (page != null ? page.hashCode() : 0);
        result = 29 * result
                + (contentResource != null ? contentResource.hashCode() : 0);
        result = 29 * result + (referrerUrl != null ? referrerUrl.hashCode() : 0);
        result = 29 * result
                + (referrerDomain != null ? referrerDomain.hashCode() : 0);
        result = 29 * result
                + (searchEngineId != null ? searchEngineId.hashCode() : 0);
        result = 29 * result + (searchPhrase != null ? searchPhrase.hashCode() : 0);
        result = 29 * result
                + (sessionNumber != null ? sessionNumber.hashCode() : 0);
        result = 29 * result
                + (visitorNumber != null ? visitorNumber.hashCode() : 0);
        result = 29 * result + (ip != null ? ip.hashCode() : 0);
        result = 29 * result + (browserId != null ? browserId.hashCode() : 0);
        result = 29 * result + (osId != null ? osId.hashCode() : 0);
        result = 29 * result + (robotId != null ? robotId.hashCode() : 0);
        result = 29 * result + (user != null ? user.hashCode() : 0);
        result = 29 * result + (screenWidth != null ? screenWidth.hashCode() : 0);
        result = 29 * result + (screenHeight != null ? screenHeight.hashCode() : 0);
        result = 29 * result + (colorDepth != null ? colorDepth.hashCode() : 0);
        result = 29 * result + (date != null ? date.hashCode() : 0);
        result = 29 * result + (entryPoint != null ? entryPoint.hashCode() : 0);
        result = 29 * result + (exitPoint != null ? exitPoint.hashCode() : 0);
        return result;
    }
}
